﻿/* 
    Lscheduler Yimfery Ma  V1.0 
    唯一标识符清单
    div_ls_body：日程表格所在的容器
    ls_content：活动内容的容器
    div_ls_editdetail:活动内容详细编辑器
    ls_divshortcut：快捷创建所在的层
    ls_shortcutcreate：快捷创建区域显示
    ls_shortcutcreate_detail：快捷创建信息显示
    ls_shortcutcreate_trigon：快捷创建三角形
    btn_ls_scc：快捷创建中创建活动的按钮
    btn_ls_scd：快捷创建中详细的按钮
    txt_ls_scc：快捷创建中活动主题的文本框
    div_ls_color_choosed：详细编辑颜色选择
    txt_ls_subject：详细编辑活动主题文本框
    txt_ls_startdate：详细编辑活动开始日期yyyy/mm/dd
    txt_ls_starttime：详细编辑活动开始时间HH:mm
    txt_ls_enddate：详细编辑活动结束日期yyyy/mm/dd
    txt_ls_endtime：详细编辑活动结束时间HH:mm
    div_ls_color_choosed：详细编辑活动颜色的选择(获取其parentNode的color属性)
    txt_ls_content：详细编辑活动内容
    btn_ls_edit：详细编辑编辑按钮
    Activity 说动对象说明
    ID：唯一标识符
    Subject：主题
    StartTime：开始时间
    EndTime：结束时间
    Content：内容
    Color：颜色
*/

var Namespace = {
    register: function (nameSpace) {
        var nsArray = nameSpace.split('.');
        var sEval = "";
        var sNS = "";
        for (var i = 0; i < nsArray.length; i++) {
            if (i != 0) sNS += ".";
            sNS += nsArray[i];
            sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = new Object();"
        }
        if (sEval != "") {
            eval(sEval);
        }
    }
}
Namespace.register("Lscheduler");
Lscheduler.viewType = {
    Date: "date",
    Week: "week",
    Month: "month",

};
Lscheduler.init = function (cfg) {
    if (cfg.currentDate) {
        this.currentDate = cfg.currentDate;
    } else {
        this.currentDate = new Date();
    }
    this.miniCal = {
        year: this.currentDate.getFullYear(),
        month: this.currentDate.getMonth()
    };
    if (cfg.interval && cfg.interval == 15) {
        this.interval = 15;
        this._interval = 3;
    }
    else {
        this.interval = 30;
        this._interval = 1;
    }
    document.body.style.height = "100%";
    document.body.style.overflow = "hidden";
    var div_top = document.createElement("div");
    div_top.style.position = "absolute";
    div_top.style.width = "100%";
    div_top.style.height = "100%";
    document.body.appendChild(div_top);
    var screenHeight = div_top.offsetHeight;
    var screenWidth = div_top.offsetWidth;
    if (screenHeight <= 300 || screenWidth <= 300) {
        document.body.innerHTML = "对不起，您现在的浏览器窗口太小，请将窗口放大";
    }
    div_top.style.position = "";
    div_top.style.width = "";
    div_top.style.height = "";
    Lscheduler.screenHeight = screenHeight;
    Lscheduler.screenWidth = screenWidth;
    this.screenHeight = screenHeight;
    this.screenWidth = screenWidth;
    div_top.className = "ls_f_top";
    var div_left = document.createElement("div");
    div_left.style.height = (screenHeight - div_top.offsetHeight) + "px";
    div_left.className = "ls_f_left";
    document.body.appendChild(div_left);
    this.initLeft(div_left);
    var div_right = document.createElement("div");
    div_right.style.height = div_left.style.height;
    div_right.style.width = (screenWidth - div_left.offsetWidth) + "px";
    div_right.className = "ls_f_right";
    document.body.appendChild(div_right);
    if (!cfg.viewType) {
        cfg.viewType = "day";
    }
    this.service = {};
    if (cfg.service) {
        if (cfg.service.create) {
            this.service.create = cfg.service.create;
        }
    }
    this.initTop(div_top, cfg.viewType);
    this.initCenter(div_right);
}

Lscheduler.init.prototype.initTop = function (topElement, viewType) {
    var that = this;
    var span_1 = document.createElement("span");
    span_1.appendChild(document.createTextNode("日历"));
    span_1.className = "ls_title";
    topElement.appendChild(span_1);
    var div_header = document.createElement("div");
    div_header.className = "ls_header";
    topElement.appendChild(div_header);
    var btn_t = Lscheduler.createButton("今日");
    div_header.appendChild(btn_t);
    var btn_prev = Lscheduler.createButton("<");
    btn_prev.className = btn_prev.className + " ls_btn_preview";
    div_header.appendChild(btn_prev);
    var btn_next = Lscheduler.createButton(">");
    btn_next.className = btn_next.className + " ls_btn_next";
    div_header.appendChild(btn_next);
    var btn_day = Lscheduler.createButton("日");
    btn_day.className = btn_day.className + " ls_btn_day";
    div_header.appendChild(btn_day);
    var btn_week = Lscheduler.createButton("周");
    btn_week.className = btn_week.className + " ls_btn_week";
    div_header.appendChild(btn_week);
    var btn_month = Lscheduler.createButton("月");
    btn_month.className = btn_month.className + " ls_btn_month";
    btn_day.onclick = function () {
        btn_day.style.backgroundColor = "#C2C2C2";
        btn_week.style.backgroundColor = "";
        btn_month.style.backgroundColor = "";
        that.changeView("day");
    }
    btn_week.onclick = function () {
        btn_day.style.backgroundColor = "";
        btn_week.style.backgroundColor = "#C2C2C2";
        btn_month.style.backgroundColor = "";
        that.changeView("week");
    }
    btn_month.onclick = function () {
        btn_day.style.backgroundColor = "";
        btn_week.style.backgroundColor = "";
        btn_month.style.backgroundColor = "#C2C2C2";
        that.changeView("month");
    }
    div_header.appendChild(btn_month);
    if (viewType == "day") {
        btn_day.click();
    }
    else if (viewType == "week") {
        btn_week.click();
    }
    else if (viewType == "month") {
        btn_month.click();
    }
}

//初始化左边的模块
Lscheduler.init.prototype.initLeft = function (leftElement) {
    var div_minical_container = document.createElement("div");
    div_minical_container.className = "ls_mini_cal_c";
    var div_minical_head = document.createElement("div");
    div_minical_head.className = "ls_mini_cal_head";
    var div_pre = document.createElement("div");
    div_pre.className = "ls_mini_act";
    div_pre.style.float = "left";
    var that = this;
    div_pre.onclick = function () {
        that.initMiniCal(null, "preview");
    }
    var span_pre = document.createElement("span");
    span_pre.className = "ls_mini_cal_prev";
    div_pre.appendChild(span_pre);
    div_minical_head.appendChild(div_pre);
    var span_mini_t = document.createElement("span");
    span_mini_t.id = "ls_mini_cal_title";
    span_mini_t.appendChild(document.createTextNode(this.miniCal.year + "年" + Lscheduler.supplyString((this.miniCal.month + 1).toString()) + "月"));
    div_minical_head.appendChild(span_mini_t);
    var div_next = document.createElement("div");
    div_next.className = "ls_mini_act";
    div_next.style.float = "right";
    var span_next = document.createElement("span");
    span_next.className = "ls_mini_cal_next";
    div_next.appendChild(span_next);
    div_next.onclick = function () {
        that.initMiniCal(null, "next");
    }
    div_minical_head.appendChild(div_next)
    leftElement.appendChild(div_minical_head);
    var tb_m_s = document.createElement("table");
    tb_m_s.id = "ls_mini_cal";
    tb_m_s.className = "ls_mini_cal";
    var tr = tb_m_s.insertRow(-1);
    tr.className = "header";
    for (var i = 0; i < Lscheduler.miniWeek.length; i++) {
        var tc_1 = tr.insertCell(-1);
        tc_1.appendChild(document.createTextNode(Lscheduler.miniWeek[i]));
    }
    div_minical_container.appendChild(tb_m_s);
    leftElement.appendChild(div_minical_container);
    this.initMiniCal(tb_m_s);
}

//初始化迷你日历的模块
Lscheduler.init.prototype.initMiniCal = function (tb_m_s, command) {
    if (!tb_m_s) {
        tb_m_s = document.getElementById("ls_mini_cal");
    }
    for (var i = tb_m_s.rows.length - 1; i >= 1; i--) {
        tb_m_s.deleteRow(i);
    }
    if (command == "preview") {
        if (this.miniCal.month == 0) {
            this.miniCal.month = 11;
            this.miniCal.year = this.miniCal.year - 1;
        }
        else {
            this.miniCal.month = this.miniCal.month - 1;
        }
    }
    else if (command == "next") {
        if (this.miniCal.month == 11) {
            this.miniCal.month = 0;
            this.miniCal.year = this.miniCal.year + 1;
        }
        else {
            this.miniCal.month = this.miniCal.month + 1;
        }
    }
    var span_minit = document.getElementById("ls_mini_cal_title");
    span_minit.innerHTML = "";
    span_minit.appendChild(document.createTextNode(this.miniCal.year + "年" + Lscheduler.supplyString((this.miniCal.month + 1).toString()) + "月"));
    var dates = Lscheduler.getFullMonthDays(this.miniCal.year, this.miniCal.month);
    var currentCell = null;
    var currentDate = new Date();
    var that = this;
    for (var i = 0; i < dates.length; i++) {
        if (i % 7 == 0) {
            tr = tb_m_s.insertRow(-1);
        }
        var td = tr.insertCell(-1);
        td.appendChild(document.createTextNode(Lscheduler.supplyString(dates[i].getDate().toString())));
        if (Lscheduler.dateEqual(dates[i], currentDate)) {
            td.style.fontWeight = "bolder";
        }
        td.onmouseover = function () {
            if (this.getAttribute("l") == "1") {
                return;
            }
            this.style.backgroundColor = "#e9e184";
        }
        td.onmouseout = function () {
            if (this.getAttribute("l") == "1") {
                return;
            }
            this.style.backgroundColor = "";
        }
        td.onclick = function () {
            if (this.getAttribute("l") == "1") {
                return;
            }
            if (currentCell) {
                currentCell.removeAttribute("l", "1");
                currentCell.style.backgroundColor = "";
                currentCell.style.color = "";
            }
            this.setAttribute("l", "1");
            this.style.backgroundColor = "#3C60F0";
            this.style.color = "#ffffff";
            currentCell = this;
            that.changeDate(new Date(that.miniCal.year, that.miniCal.month, Lscheduler.getText(currentCell), 0, 0, 0));
        }
        if (Lscheduler.dateEqual(this.currentDate, dates[i])) {
            td.click();
        }
    }
}

//初始化中间的模块
Lscheduler.init.prototype.initCenter = function (centerElement) {
    if (this.viewType == "day") {
        this.initDayView(centerElement);
    }
    this.appendActivity({ ID: 1, Subject: "我的活动", StartTime: new Date(2013, 7, 24, 3, 5), EndTime: new Date(2013, 7, 24, 5, 15), Color: "#5484ed" });
}

//初始化日视图
Lscheduler.init.prototype.initDayView = function (centerElement) {
    var divc = document.createElement("div");
    divc.style.width = (centerElement.offsetWidth - 20) + "px";
    divc.className = "ls_div_bc";
    centerElement.appendChild(divc);
    var tbh = document.createElement("table");
    tbh.className = "ls_tb_header";
    var tr = tbh.insertRow(-1);
    var td = tr.insertCell(-1);
    td.style.textAlign = "center";
    td.appendChild(document.createTextNode(Lscheduler.getTitleText(this.currentDate)));
    tr = tbh.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.border = "1px solid #E6E6E6";
    var divh = document.createElement("div");
    divh.className = "ls_tb_h_d";
    td.appendChild(divh);
    var tbhh = document.createElement("table");
    tbhh.id = "tb_allday";
    tr = tbhh.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = "20px";
    divh.appendChild(tbhh);
    divc.appendChild(tbh);
    var divbody = document.createElement("div");
    divbody.id = "div_ls_body";
    divbody.style.marginTop = "2px";
    divbody.style.height = (centerElement.offsetHeight - tbh.offsetHeight - 7) + "px";
    divbody.style.borderLeft = "1px solid #E6E6E6";
    divbody.style.borderTop = "1px solid #E6E6E6";
    divbody.style.borderBottom = "1px solid #E6E6E6";
    divbody.style.overflowY = "auto";
    divc.appendChild(divbody);
    var tbbody = document.createElement("table");
    divbody.appendChild(tbbody);
    tbbody.className = "ls_tb_body";
    tr = tbbody.insertRow(-1);
    tr.style.height = "1px";
    var td_1 = tr.insertCell(-1);
    td_1.style.width = "60px";
    var td_21 = tr.insertCell(-1);
    this.createTimeMasks(td_21);
    tr = tbbody.insertRow(-1);
    td_1 = tr.insertCell(-1);
    td_1.style.lineHeight = "62px";
    td_1.style.textAlign = "right";
    for (var i = 0; i < 24; i++) {
        var divt = document.createElement("div");
        if (i != 23) {
            divt.style.borderBottom = "1px solid #E6E6E6";
        }
        divt.style.borderRight = "1px solid #E6E6E6";
        divt.style.height = (this.interval == 15 ? "63px" : "61px");
        divt.style.paddingRight = "5px";
        divt.appendChild(document.createTextNode(i));
        td_1.appendChild(divt);
    }
    var td_2 = tr.insertCell(-1);
    td_2.style.verticalAlign = "top";
    var divcontent = document.createElement("div");
    divcontent.style.height = tbbody.offsetHeight + "px";
    divcontent.style.width = "100%";
    divcontent.style.zIndex = 3;
    divcontent.id = "ls_content";
    var that = this;
    divcontent.onclick = function (e) {
        var s = Math.round(e.offsetY);
        var temp = (that.interval == 15 ? 64 : 62);
        var m = s % temp;
        that.showShortcutCreate(e, parseInt(s / temp), (m - parseInt(m / that.interval)), this);
        Lscheduler.stopBubble(e);
    }
    divcontent.style.position = "relative";
    td_2.appendChild(divcontent);
    divcontent = document.createElement("div");
    divcontent.style.height = tbbody.offsetHeight + "px";
    divcontent.style.width = "100%";
    divcontent.style.zIndex = 4;
    divcontent.id = "ls_divshortcut";
    divcontent.style.marginTop = -tbbody.offsetHeight + "px";
    td_2.appendChild(divcontent);
}

//创建小时的横线
Lscheduler.init.prototype.createTimeMasks = function (cell) {
    var that = this;
    var div_1 = document.createElement("div");
    div_1.style.marginTop = "1px";
    div_1.style.position = "relative";
    cell.appendChild(div_1);
    var div_2 = document.createElement("div");
    div_2.style.position = "absolute";
    div_2.style.width = "100%";
    div_2.style.zIndex = 1;
    div_1.appendChild(div_2);
    for (var i = 0; i < 24; i++) {
        var div1 = document.createElement("div");
        div1.style.height = (this.interval == 15 ? "63px" : "61px");
        div1.style.borderBottom = "1px solid #E6E6E6";
        for (var j = 0; j < this._interval; j++) {
            var div11 = document.createElement("div");
            div11.style.height = this.interval + "px";
            div11.style.borderBottom = "1px dotted #E6E6E6";
            div1.appendChild(div11);
        }
        div_2.appendChild(div1);
    }
}

//日期变更
Lscheduler.init.prototype.changeDate = function (date) {
    if (Date.dateEqual(this.currentDate, date)) {
        return;
    }

}

//参数 e:事件 source：触发的元素 hour:小时 interval:间隔 isp:是否显示局部
Lscheduler.init.prototype.showShortcutCreate = function (e, hours, minutes, container) {
    var con = document.getElementById("ls_divshortcut");
    var div = document.getElementById("ls_shortcutcreate");
    if (!div) {
        div = document.createElement("div");
        div.onclick = function (e) {
            Lscheduler.stopBubble(e);
        }
        div.id = "ls_shortcutcreate";
        if (this.interval == 15) {
            div.style.height = "23px";
        }
        else {
            div.style.height = "50px";
        }
        div.className = "ls_shortcutc";
        con.appendChild(div);
    }
    else {
        div.style.display = "";
    }
    div.innerHTML = "";
    minutes = minutes - this.interval;
    var temp = 0;
    do {
        if (minutes <= temp) {
            break;
        }
        temp = temp + this.interval;
    }
    while (true);
    var starttime = Lscheduler.supplyString(hours) + ":" + Lscheduler.supplyString(temp);
    div.style.top = (hours * (this.interval == 15 ? 64 : 62) + temp + parseInt((temp % this.interval)) + 1) + "px";
    temp = temp + 2 * this.interval;
    if (temp >= 60) {
        temp = temp - 60;
        hours = hours + 1;
    }
    var endtime = Lscheduler.supplyString(hours) + ":" + Lscheduler.supplyString(temp);
    div.appendChild(document.createTextNode(starttime + "-" + endtime));
    div.style.width = (container.offsetWidth - 2) + "px";
    var pos = Lscheduler.getPosition(div);
    var div1 = document.getElementById("ls_shortcutcreate_detail");
    var div2 = document.getElementById("ls_shortcutcreate_trigon");
    if (!div1) {
        var div1 = document.createElement("div");
        div1.onclick = function (e) {
            Lscheduler.stopBubble(e);
        }
        div1.className = "ls_shortcutd";
        div1.style.zIndex = 12;
        div1.id = "ls_shortcutcreate_detail";
        document.body.appendChild(div1);
        var div11 = document.createElement("div");
        div11.style.margin = "10px 10px 10px 20px";
        div1.appendChild(div11);
        var div111 = document.createElement("div");
        div111.appendChild(document.createTextNode("时间："));
        div11.appendChild(div111);
        var label = document.createElement("label");
        label.id = "lbl_ls_sct";
        div111.appendChild(label);
        var close1 = Lscheduler.createElement("div", null, { height: "17px", width: "17px", float: "right", cursor: "pointer" });
        div111.appendChild(close1);
        close1.onmouseover = function () {
            this.childNodes[0].className = "ls_icon_close2";
            this.style.backgroundColor = "#0072C6";
        }
        close1.onmouseout = function () {
            this.childNodes[0].className = "ls_icon_close1";
            this.style.backgroundColor = "";
        }
        close1.onclick = function () {
            Lscheduler.hideShortCut();
        }
        var close2 = Lscheduler.createElement("div", { className: "ls_icon_close1" }, { margin: "2px" });
        close1.appendChild(close2);
        div111 = document.createElement("div");
        div111.style.marginTop = "10px";
        div111.appendChild(document.createTextNode("主题："));
        div11.appendChild(div111);
        var textbox = document.createElement("input");
        textbox.type = "text";
        textbox.style.width = "223px";
        textbox.className = "ls_txt";
        textbox.id = "txt_ls_scc";
        div111.appendChild(textbox);
        div111 = document.createElement("div");
        div111.style.margin = "10px 10px 0px 0px";
        div111.style.float = "right";
        var v1111 = Lscheduler.createButton("创建活动");
        v1111.id = "btn_ls_scc";
        div111.appendChild(v1111);
        var v1112 = Lscheduler.createAnchor("详细》");
        v1112.id = "btn_ls_scd";
        v1112.style.marginLeft = "10px";
        div111.appendChild(v1112);
        div11.appendChild(div111);
        div2 = document.createElement("div");
        div2.onclick = function (e) {
            Lscheduler.stopBubble(e);
        }
        div2.id = "ls_shortcutcreate_trigon";
        div2.className = "ls_trigon";
        div2.style.position = "absolute";
        div11 = document.createElement("div");
        div11.className = "ls_trigon_1";
        div2.appendChild(div11);
        div2.style.zIndex = 13;
        document.body.appendChild(div2);
        Lscheduler.hideShortCut = function () {
            document.getElementById("ls_shortcutcreate").style.display = "none";
            document.getElementById("ls_shortcutcreate_detail").style.display = "none";
            document.getElementById("ls_shortcutcreate_trigon").style.display = "none";
            Lscheduler.removeEvent(document.body, "click", Lscheduler.hideShortCut);
        }
    }
    else {
        div1.style.display = "";
        div2.style.display = "";
        Lscheduler.removeEvent(document.body, "click", Lscheduler.hideShortCut);
        Lscheduler.attachEvent(document.body, "click", Lscheduler.hideShortCut);
    }
    var sc = document.getElementById("div_ls_body").scrollTop;
    var divpos = pos.x - 123 - sc;
    if (divpos < 0) {
        div1.style.top = "0px";
        div2.style.top = (pos.x - 11 - divpos - sc) + "px";
    }
    else {
        div1.style.top = divpos + "px";
        div2.style.top = (pos.x - 11 - sc) + "px";
    }
    div1.style.left = (pos.y - 20) + "px";
    div2.style.left = (pos.y + 30) + "px";
    var label = document.getElementById("lbl_ls_sct");
    label.innerHTML = "";
    label.appendChild(document.createTextNode(Lscheduler.getTitleText_zhcn(this.currentDate) + starttime + "-" + endtime));
    document.getElementById("txt_ls_scc").focus();
    var date = Lscheduler.getDate(this.currentDate);
    var that = this;
    document.getElementById("btn_ls_scc").onclick = function () {
        this.disabled = "disabled";
        var subject = Lscheduler.trim(document.getElementById("txt_ls_scc").value);
        if (subject == "") {
            this.disabled = "";
            document.getElementById("txt_ls_scc").focus();
            return;
        }
        var startTime = Lscheduler.parseDate(date + " " + starttime);
        var endTime = Lscheduler.parseDate(date + "" + endtime);
        if (endTime > startTime || endtime > new Date(starttime.valueOf() + 15 * 60 * 1000)) {
            return;
        }
        that.createActivity({
            Subject: subject,
            StartTime: date + " " + starttime,
            EndTime: date + " " + endtime,
            Color: Lscheduler.colorSet[0].value,
            Content: ""
        }, function (result) {
            document.getElementById("txt_ls_scc").value = "";
            div.style.display = "none";
            div1.style.display = "none";
            div2.style.display = "none";
            Lscheduler.Message.alert("保存成功");
        }, null, function () {
            document.getElementById("btn_ls_scc").disabled = "";
        });
    }
    document.getElementById("btn_ls_scd").onclick = function () {
        var div = document.getElementById("div_ls_editdetail");
        if (!div) {
            div = document.createElement("div");
            div.id = "div_ls_editdetail";
            div.style.height = that.screenHeight + "px";
            div.style.width = that.screenWidth + "px";
            div.style.position = "absolute";
            div.style.top = "0px";
            div.style.left = "100px";
            div.style.backgroundColor = "#FDFFFF";
            div.style.zIndex = 20;
            var v = document.createElement("div");
            v.style.margin = "10px 0px 10px 30px";
            v.style.float = "left";
            div.appendChild(v);
            var v1 = Lscheduler.getImitateButton();
            v.appendChild(v1);
            var v11 = document.createElement("div");
            v11.className = "ls_icon_back";
            v11.style.margin = "7px 0px 0px 34px";
            v1.appendChild(v11);
            v1.onclick = function () {
                Lscheduler.stopBubble(e)
                Lscheduler.moveRight(div, 0, -that.screenWidth);
            }
            v1 = Lscheduler.getImitateButton();
            v1.style.marginLeft = "20px";
            v1.id = "btn_ls_edit";
            v1.appendChild(document.createTextNode("创建"));
            v.appendChild(v1);
            v1.onclick = function () {
                if (this.getAttribute("doing")) {
                    return;
                }
                var sbj = Lscheduler.trim(document.getElementById("txt_ls_subject").value);
                if (sbj == "") {
                    return;
                }
                var stm = Lscheduler.parseDate(Lscheduler.trim(document.getElementById("txt_ls_startdate").value) + " " + Lscheduler.trim(document.getElementById("txt_ls_starttime").value));
                var etm = Lscheduler.trim(document.getElementById("txt_ls_enddate").value) + " " + Lscheduler.trim(document.getElementById("txt_ls_endtime").value);
                var startTime = Lscheduler.parseDate(stm);
                var endTime = Lscheduler.parseDate(etm);
                if (endTime > startTime || endtime > new Date(starttime.valueOf() + 15 * 60 * 1000)) {
                    return;
                }
                var pn = document.getElementById("div_ls_color_choosed");
                if (!(pn && pn.parentNode)) {
                    return;
                }
                else {
                    pn = pn.parentNode.getAttribute("color");
                }
                this.setAttribute("doing", "1");
                that.createActivity({
                    Subject: sbj,
                    StartTime: stm,
                    EndTime: etm,
                    Color: pn,
                    Content: Lscheduler.trim(document.getElementById("txt_ls_content").value)
                }, function (result) {
                    if (result.Result == "Success") {
                        alert("保存成功");
                    }
                    else {
                        alert(result.Message);
                    }
                }, null, function () {
                    document.getElementById("btn_ls_edit").removeAttribute("doing");
                });
            }
            v = document.createElement("div");
            v.className = "ls_split_line";
            v.style.float = "left";
            div.appendChild(v);
            v = document.createElement("div");
            v.style.margin = "10px 0px 10px 30px";
            v.style.float = "left";
            div.appendChild(v);
            v1 = document.createElement("div");
            v.appendChild(v1);
            v11 = Lscheduler.getTextbox();
            v11.style.width = "600px";
            v11.style.fontSize = "16px";
            v11.id = "txt_ls_subject";
            v1.appendChild(v11);
            v1 = document.createElement("div");
            v1.style.marginTop = "5px";
            v.appendChild(v1);
            v11 = Lscheduler.getTextbox();
            v11.style.width = "80px";
            v11.style.imeMode = "disabled";
            v11.onpaste = function () {
                return false;
            }
            v11.onfocus = function () {
                Lscheduler.calendar.pick(this);
            }
            v11.id = "txt_ls_startdate";
            v1.appendChild(v11);
            v11 = Lscheduler.getTextbox();
            v11.style.width = "42px";
            v11.style.marginLeft = "5px";
            v11.style.imeMode = "disabled";
            v11.onpaste = function () {
                return false;
            }
            v11.id = "txt_ls_starttime";
            Lscheduler.registerTimeLimit(v11);
            v1.appendChild(v11);
            v11 = document.createElement("span");
            v11.appendChild(document.createTextNode("到"));
            v11.style.fontSize = "13px";
            v11.style.margin = "0px 5px 0px 5px";
            v1.appendChild(v11);
            v11 = Lscheduler.getTextbox();
            v11.style.width = "80px";
            v11.id = "txt_ls_enddate";
            v11.style.imeMode = "disabled";
            v11.onpaste = function () {
                return false;
            }
            v11.onfocus = function () {
                Lscheduler.calendar.pick(this);
            }
            v1.appendChild(v11);
            v11 = Lscheduler.getTextbox();
            v11.style.width = "42px";
            v11.style.marginLeft = "5px";
            v11.id = "txt_ls_endtime";
            Lscheduler.registerTimeLimit(v11);
            v11.style.imeMode = "disabled";
            v11.onpaste = function () {
                return false;
            }
            v1.appendChild(v11);
            v1 = document.createElement("div");
            v1.style.marginTop = "5px";
            v.appendChild(v1);
            v11 = document.createElement("table");
            v11.style.fontSize = "13px";
            v1.appendChild(v11);
            var v111 = v11.insertRow(-1);
            v1111 = v111.insertCell(-1);
            v1111.className = "ls_topright";
            v1111.appendChild(document.createTextNode("活动颜色："));
            v1111 = v111.insertCell(-1);
            for (var i = 0; i < Lscheduler.colorSet.length; i++) {
                var v1111_1 = document.createElement("div");
                v1111_1.className = "ls_color_dis";
                v1111_1.style.backgroundColor = Lscheduler.colorSet[i].value;
                v1111_1.style.border = "1px solid " + Lscheduler.colorSet[i].value;
                v1111_1.setAttribute("color", Lscheduler.colorSet[i].value);
                v1111_1.title = Lscheduler.colorSet[i].name;
                v1111_1.onmouseover = function () {
                    this.style.borderColor = "#000000";
                }
                v1111_1.onmouseout = function () {
                    this.style.borderColor = this.getAttribute("color");
                }
                v1111_1.onclick = function () {
                    var choosed = document.getElementById("div_ls_color_choosed");
                    if (!choosed) {
                        choosed = document.createElement("div");
                        choosed.id = "div_ls_color_choosed";
                        choosed.style.margin = "3px 0px 0px 2px";
                        choosed.className = "ls_color_choosed";
                    }
                    this.appendChild(choosed);
                }
                v1111.appendChild(v1111_1);
                if (i == 0) {
                    v1111_1.click();
                }
            }
            v111 = v11.insertRow(-1);
            v1111 = v111.insertCell(-1);
            v1111.style.height = "3px";
            v1111 = v111.insertCell(-1);
            v111 = v11.insertRow(-1);
            v1111 = v111.insertCell(-1);
            v1111.className = "ls_topright";
            v1111.appendChild(document.createTextNode("活动内容："));
            v1111 = v111.insertCell(-1);
            var v11111 = document.createElement("textarea");
            v11111.style.resize = "none";
            v11111.className = "ls_txt1";
            v11111.style.height = "100px";
            v11111.style.width = "528px";
            v11111.id = "txt_ls_content";
            v1111.appendChild(v11111);
        }
        document.body.appendChild(div);
        document.getElementById("txt_ls_startdate").value = date;
        document.getElementById("txt_ls_starttime").value = starttime;
        document.getElementById("txt_ls_enddate").value = date;
        document.getElementById("txt_ls_endtime").value = endtime;
        Lscheduler.moveRight(div, that.screenWidth, 0, function () {
            document.getElementById("txt_ls_subject").focus();
        });
    }
}


Lscheduler.init.prototype.changeView = function (viewType) {
    if (this.viewType == viewType) {
        return;
    }
    this.viewType = viewType;

}

Lscheduler.init.prototype.createActivity = function (activity, success, error, complete) {
    if (activity.Subject == "") {
        return;
    }
    var that = this;
    Lscheduler.ajax({
        url: this.service.create,
        data: {
            subject: activity.Subject,
            starttime: activity.StartTime,
            endtime: activity.EndTime,
            color: activity.Color,
            content: activity.Content
        },
        type: "post",
        success: function (result) {
            if (success) {
                success(Lscheduler.parseJson(result));
                that.appendActivity(activity);
            }
        },
        error: error,
        complete: complete
    });
}

//参数 activity:活动对象
Lscheduler.init.prototype.appendActivity = function (activity) {
    //var div = Lscheduler.getActivityContainer(activity.Color);
    //div.style.width = "100px";
    //var sh = this.getHeight(activity.StartTime);
    //var eh = this.getHeight(activity.EndTime);
    //div.style.top = sh + "px";
    //div.style.height = (eh - sh - 3) + "px"
    //document.getElementById("ls_content").appendChild(div);
}

Lscheduler.init.prototype.getHeight = function (time) {
    return (this.interval == 15 ? 64 : 62) * time.getHours() + (parseInt(time.getMinutes() / this.interval)) * 16 + (time.getMinutes() % 15);
}

Lscheduler.init.prototype.loadActivites = function () {

}